import { simHttp } from "@/util/httpClient/SimulationHttpClient";
import { SimulateController } from "./Controller";

class SimApi {

  controller: SimulateController;

  constructor(c: SimulateController) {
    this.controller = c;
  }

  hello (data: { timeout: number }) {
    return simHttp.get({
      api: 'hello'
    }, data);
  }

  simulationLoad (data: { projectId: string, modelIds: string[] }) {
    return simHttp.post({
      api: 'simulation/load',
      data
    });
  }

  simulationInit (data: { modelId: string, simulationSessionId: string, type: string }) {
    return simHttp.post({
      api: 'simulation/init',
      data,
    });
  }

  simulationStart (simulationSessionId: string) {
    return simHttp.post({
      api: 'simulation/start',
      data: { simulationSessionId }
    });
  }

  simulationStartStep (simulationSessionId: string) {
    return simHttp.get({
      api: 'simulation/startStep',
      data: { simulationSessionId }
    });
  }

  simulationSuspend (simulationSessionId: string) {
    return simHttp.get({
      api: 'simulation/suspend',
      data: { simulationSessionId }
    });
  }

  simulationResume (simulationSessionId: string) {
    return simHttp.get({
      api: 'simulation/resume',
      data: { simulationSessionId }
    });
  }

  simulationNext (simulationSessionId: string) {
    return simHttp.get({
      api: 'simulation/next',
      data: { simulationSessionId }
    });
  }

  simulationStop (simulationSessionId: string) {
    return simHttp.get({
      api: 'simulation/stop',
      data: { simulationSessionId }
    });
  }

  simulationUpdateSpeed (data: SimulationUpdateSpeedParam) {
    return simHttp.get({
      api: 'simulation/updateSpeed',
      data
    });
  }

  consoleChangeLocale (language: string) {
    this.controller.lang = language;
    return simHttp.get({
      api: 'console/changeLocale',
      data: { language }
    });
  }

  consoleSetRecordLevel (level: string) {
    return simHttp.get({
      api: 'console/setRecordLevel',
      data: { level }
    });
  }

  matlabRun(data: MatlabRunParam) {
    return simHttp.get({
      api: 'matlab/run',
      data
    });
  }

  simulationCreateSequenceDiagram(data: SimulationCreateSequenceDiagramParam) { // 序列图创建
    return simHttp.get({
      api: 'simulation/createSequenceDiagram',
      data
    });
  }

  simulationGetVariableContent(data: SimulationGetVariableContentParam) { // 变量提示
    return simHttp.get({
      api: 'simulation/getVariableContent',
      data
    });
  }

  sceneGetSignalBySceneSession(data: SceneGetSignalBySceneSessionParam) {
    return simHttp.get({
      api: 'scene/getSignalBySceneSession',
      data
    });
  }

  sceneSendSignalBySceneSession(data: SceneSendSignalBySceneSessionParam) {
    return simHttp.get({
      api: 'scene/sendSignalBySceneSession',
      data
    });
  }

  simulationUpdateMatlabVersion(data: SimulationUpdateMatlabVersionParam) {
    return simHttp.post({
      api: 'simulation/updateMatlabVersion',
      data,
    });
  }

  sceneFetch(data: SceneFetchParam) {
    data.fetchAll = data.fetchAll || false;
    return simHttp.post({
      api: 'scene/fetch',
      data,
    });
  }

  variableGetVariableBySceneSession(data: VariableGetVariableBySceneSessionParam) {
    data.fetchAll = data.fetchAll || false;
    return simHttp.get({
      api: 'variable/getVariableBySceneSession',
      data,
    });
  }

  variableUpdate(data: VariableUpdateParamParam) {
    return simHttp.post({
      api: 'variable/update',
      data,
    });
  }

  variableRemove(data: RemoveUpdateParamParam) {
    return simHttp.post({
      api: 'variable/remove',
      data,
    });
  }

  variableGetVariableValueByValueId(data: VariableGetVariableValueByValueIdParam) {
    return simHttp.get({
      api: 'variable/getVariableValueByValueId',
      data,
    });
  }

  variableGetVariableByValueId(data: variableGetVariableByValueIdParam) { // no sceneId
    return simHttp.get({
      api: 'variable/getVariableByValueId',
      data,
    });
  }

  uiGetInitData(data: UiGetInitDataParam) {
    return simHttp.get({
      api: 'ui/getInitData',
      data,
    });
  }

  simulationConfig(data: SimulationConfigParam) {
    return simHttp.get({
      api: 'simulation/config',
      data,
    });
  }

  simulationCheckModelChange (projectId: string) {
    return simHttp.get({
      api: 'simulation/checkModelChange',
      data: { projectId }
    });
  }

  variableExport (data: VariableExportParam) {
    return simHttp.get({
      api: 'variable/export',
      data,
    });
  }

  variableExportToExisted (data: VariableExportToExistedParam) {
    return simHttp.get({
      api: 'variable/exportToExisted',
      data
    });
  }

  instancetableEvaluateInstanceTable (data: InstancetableParam) {
    return simHttp.get({
      api: 'instancetable/evaluateInstanceTable',
      data
    });
  }

  instancetableEvaluateInfoFlowTable (data: InstancetableEvaluateInfoFlowTableParam) {
    return simHttp.post({
      api: 'instancetable/evaluateInfoFlowTable',
      data
    });
  }

  instancetableEvaluateInstanceTableWithBehavior (data: InstancetableParam) {
    return simHttp.get({
      api: 'instancetable/evaluateInstanceTableWithBehavior',
      data,
    });
  }

  consoleActiveExportSet(p: boolean) {
    return simHttp.post({
      api: 'console/activeExportSet',
      data: {
        activeExport: p,
      }
    });
  }

  uiUpdatePropertyValue(data: UiUpdatePropertyValueParam) {
    return simHttp.get({
      api: 'ui/updatePropertyValue',
      data
    });
  }

  uiClickButton(data: UiClickButtonParam) {
    return simHttp.get({
      api: 'ui/clickButton',
      data
    });
  }

  timeserieschartGetTscLineData(data: TimeserieschartGetTscLineDataParam) {
    return simHttp.get({
      api: 'timeserieschart/getTscLineData',
      data
    });
  }

  timeLineChatGetNodeLineData(data: TimeLineChatGetNodeLineDataParam) {
    return simHttp.get({
      api: 'timeLineChat/getTimeLineData',
      data
    });
  }
}

export default SimApi;

export type SimulationLoadParam = {
  projectId: string
  matlabVersion: string
}

export type SimulationUpdateSpeedParam = {
  speed: number
  simulationSessionId: string
}

export type MatlabRunParam = {
  formulas: { id: string, expression: string }[]
  matlabVersionNO: string
}

export type SimulationCreateSequenceDiagramParam = {
  simulationSessionId: string
  modelId: string
  diagramModelId: string
}

export type SimulationGetVariableContentParam = {
  simulationSessionId: string
  modelId: string
  sceneSessionId: string
}

export type SceneGetSignalBySceneSessionParam = {
  sceneSessionId: string
  simulationSessionId: string
}

export type SceneSendSignalBySceneSessionParam = {
  signalId: string
  sceneSessionId: string
  simulationSessionId: string
}

export type SimulationUpdateMatlabVersionParam = {
  path: string
  version: string
}

export type SceneFetchParam = {
  fetchAll?: boolean
  simulationSessionId: string
}

export type VariableGetVariableBySceneSessionParam = {
  fetchAll?: boolean
  sceneId?: string
  simulationSessionId: string
}

export type VariableUpdateParamParam = {
  simulationSessionId: string
  sceneId: string
  inputValue?: string
  valueId: string
  index?: number
}

export type RemoveUpdateParamParam = {
  simulationSessionId: string
  sceneId: string
  valueId: string
  index: number
}

export type VariableGetVariableValueByValueIdParam = {
  simulationSessionId: string
  valueId: string
  sceneId: string
}

export type variableGetVariableByValueIdParam = {
  simulationSessionId: string,
  valueId: string
}

export type UiGetInitDataParam = {
  objectId: string
  projectId: string
  simulationSessionId: string
}

export type SimulationConfigParam = {
  autoStart: boolean
  autostartActiveObjects: boolean
  fumlDecision: boolean
  silent: boolean
  speed: number
  simulationSessionId: string
  designVersion: string
}

export type VariableExportParam = {
  simulationSessionId: string
  sceneSessionId: string
  valueId?: string
  mountPoint: string
}

export type VariableExportToExistedParam = {
  simulationSessionId: string
  sceneSessionId: string
  valueId: string
  mountPoint: string
}

export type InstancetableParam = {
  simulationSessionId: string
  instanceIds: string[]
}

export type UiUpdatePropertyValueParam = {
  objectId: string
  propertyId: string
  simulationSessionId: string
  values: any[]
}

export type UiClickButtonParam = {
  elementId: string
  simulationSessionId: string
  contextId: string
  modelId: string
}

export type InstancetableEvaluateInfoFlowTableParam = {
  simulationSessionId: string
  instanceIds: string[]
}

export type TimeserieschartGetTscLineDataParam = {
  simulationSessionId: string
  instanceId: string
  propertyIds: string[]
}

export type TimeLineChatGetNodeLineDataParam = {
  simulationSessionId: string,
  representsId: string,
  timelineMode: "state" | "activity",
  contextPlot: boolean,
  ignoredElementsId: string,
}